package com.lhd.web.admin;

import com.lhd.po.Type;
import com.lhd.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created by liuhandong on 2022/4/20.
 */

@RestController
public class TypeController {

    @Autowired
    private TypeService typeService;

    @GetMapping("/admin/type/{id}/delete")
    public Long deleteType(@PathVariable Long id) {
        return typeService.deleteType(id);
    }

    @PostMapping("/admin/type/post")
    public Integer postType(@RequestBody Type type){
        Integer res;
        if (type.getId() < 0){
            type.setId((long) (typeService.getMaxTypeId()+1));
            res = typeService.saveType(type);
        }else {
            res = typeService.updateType(type.getId(),type);
        }
        return res;
    }
}
